home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Applications / Lookup 1.0d2 / Includes / CList.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-27  |  2.0 KB  |  110 lines  |  [TEXT/CWIE]

  1. /*
  2.     CList.h
  3. */
  4.  
  5. #pragma once
  6.  
  7. #include <LList.h>
  8. #include <LListIterator.h>
  9.  
  10. // ------------------------------------------------------------
  11. // TEMPLATE CLASS CList
  12.  
  13. template <class T>
  14. class CList : public LList
  15. {
  16. public:
  17.     CList();
  18.  
  19.     T *        ItemAt(Int32 inAtIndex) const;
  20.  
  21.     void    InsertAt(Uint32 inCount, Int32 inAtIndex, T *inItem);
  22.     void    InsertLast(T * inItem);
  23.  
  24.     Int32    IndexOf(const T *inItem) const;
  25.     void    RemoveItem(const T *inItem);
  26. };
  27.  
  28. // ------------------------------------------------------------
  29. // TEMPLATE CLASS CListIterator
  30.  
  31. template <class T>
  32. class CListIterator
  33. {
  34. public:
  35.     CListIterator(CList<T> &inList, Int32 inPosition);
  36.     
  37.     Boolean Current(T * & outItem);
  38.     Boolean Next(T * & outItem);
  39.     Boolean Previous(T * & outItem);
  40.  
  41. private:
  42.     LListIterator    mIterator;
  43. };
  44.  
  45. // ----------------------------------------------------------------
  46.  
  47. template <class T>
  48. inline CList<T>::CList() 
  49.     : LList(sizeof(T *))
  50. {
  51. }
  52.  
  53. template <class T>
  54. T * CList<T>::ItemAt(Int32 inAtIndex) const
  55. {
  56.     T * result;
  57.     
  58.     if(FetchItemAt(inAtIndex, &result))
  59.         return result;
  60.     else
  61.         return nil;
  62. }
  63.  
  64. template <class T>
  65. void CList<T>::InsertAt(Uint32 inCount, Int32 inAtIndex, T *inItem)
  66. {
  67.     InsertItemsAt(inCount, inAtIndex, &inItem);
  68. }
  69.  
  70. template <class T>
  71. void CList<T>::InsertLast(T * inItem)
  72. {
  73.     InsertItemsAt(1, arrayIndex_Last, &inItem);
  74. }
  75.  
  76. template <class T>
  77. Int32 CList<T>::IndexOf(const T *inItem) const
  78. {
  79.     return FetchIndexOf(&inItem);
  80. }
  81.  
  82. template <class T>
  83. void CList<T>::RemoveItem(const T *inItem)
  84. {
  85.     Remove(&inItem);
  86. }
  87.  
  88. template <class T>
  89. inline CListIterator<T>::CListIterator(CList<T> &inList, Int32 inPosition)
  90.     : mIterator(inList, inPosition)
  91. {}
  92.  
  93. template <class T>
  94. inline Boolean CListIterator<T>::Current(T * &outItem)
  95. {
  96.     return mIterator.Current((void *)&outItem);
  97. }
  98.  
  99. template <class T>
  100. inline Boolean CListIterator<T>::Next(T * &outItem)
  101. {
  102.     return mIterator.Next((void *)&outItem);
  103. }
  104.  
  105. template <class T>
  106. inline Boolean CListIterator<T>::Previous(T * &outItem)
  107. {
  108.     return mIterator.Previous((void *)&outItem);
  109. }
  110.